20
Easy2Siksha
Example of Merge Sort
Let’s sort this list: [38, 27, 43, 3, 9, 82, 10]
Step 1: Divide
• Split the list into two halves:
o Left Half: [38, 27, 43]
o Right Half: [3, 9, 82, 10]
• Keep dividing each half recursively:
o Left Half: [38, 27, 43] → [38] and [27, 43] → [38], [27], [43]
o Right Half: [3, 9, 82, 10] → [3, 9] and [82, 10] → [3], [9], [82], [10]
At the end of this step, we have individual elements:
[38], [27], [43], [3], [9], [82], [10]
Step 2: Merge
Now, merge the single-element lists in sorted order:
1. Merge [27] and [43] → [27, 43]
2. Merge [38] and [27, 43] → [27, 38, 43]
Similarly, for the right half:
1. Merge [3] and [9] → [3, 9]
2. Merge [82] and [10] → [10, 82]
3. Merge [3, 9] and [10, 82] → [3, 9, 10, 82]
Step 3: Final Merge
Finally, merge the two sorted halves:
• Merge [27, 38, 43] and [3, 9, 10, 82] → [3, 9, 10, 27, 38, 43, 82]
Detailed Walkthrough
To make this even simpler, think of it like organizing a line of kids based on their height. You
break the kids into smaller groups, arrange each group, and then line them up together in
order.
• First, split them into groups of 1.
• Then merge small groups while ensuring they’re in order.
• Gradually, all the kids are sorted!